package com.iterative.system.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.iterative.common.persistence.HibernateDao;
import com.iterative.system.entity.UserRole;
@Repository
public class UserRoleDao extends HibernateDao<UserRole, Long>{

	/**
	 * 查询用户拥有的角色id集合
	 * @param userId
	 * @return 结果集合
	 */
	public List<Long> findRoleIds(Long userId) {
		String hql="select ur.roleId from UserRole ur where ur.userId=?0";
		Query query= createQuery(hql, userId);
		return query.list();
	}

	
	/**
	 * 删除用户角色
	 * @param userId
	 * @param roleId
	 */
	public void deleteUR(Long userId, Long roleId) {
		String hql="delete UserRole ur where ur.userId=?0 and ur.roleId=?1";
		batchExecute(hql, userId,roleId);
	}

}
